package io.renren.modules.generator.service.impl;

import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.renren.modules.generator.dao.SequenceDao;
import io.renren.modules.generator.service.SequenceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created with IntelliJ IDEA.
 * User: 齐丹枫
 * Date: 2019/1/17
 * Time: 9:44
 * To change this template use File | Settings | File Templates.
 * Description:
 */
@Service
public class SequenceServiceImpl extends ServiceImpl<SequenceDao, Integer> implements SequenceService{

    @Autowired
    private SequenceDao sequenceDao;

    @Override
    public String getCurrentValue(String name, int length) {
        Integer currentValue = sequenceDao.getCurrentValue(name);
        String result = currentValue.toString();
        for (int i = 0; i < (length-currentValue.toString().length()); i++) {
            result ="0"+result;
        }
        return result;
    }

    @Override
    public String getNextValue(String name, int length) {
        Integer nextValue = sequenceDao.getNextValue(name);
        String result = nextValue.toString();
        for (int i = 0; i < (length-nextValue.toString().length()); i++) {
            result ="0"+result;
        }
        return result;
    }

    @Override
    public void setCurrentValue(String name, String value) {
        sequenceDao.setCurrentValue(name,value);
    }
}
